package com.ruoyi.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.system.domain.vo.TBsCalendarVo;
import com.ruoyi.system.domain.bo.TBsCalendarBo;
import com.ruoyi.system.service.ITBsCalendarService;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;

import java.util.List;
import java.util.Arrays;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.servlet.http.HttpServletResponse;

/**
 * 工作日控制器
 * 前端访问路由地址为:/system/bsCalendar
 *
 * @author chq
 * @date 2025-06-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/bsCalendar")
public class TBsCalendarController extends BaseController {

    private final ITBsCalendarService iTBsCalendarService;

    /**
     * 查询工作日列表
     */
    @SaCheckPermission("system:bsCalendar:list")
    @GetMapping("/list")
    public TableDataInfo<TBsCalendarVo> list(TBsCalendarBo bo, PageQuery pageQuery) {
        return iTBsCalendarService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出工作日列表
     */
    @SaCheckPermission("system:bsCalendar:export")
    @Log(title = "工作日", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TBsCalendarBo bo, HttpServletResponse response) {
        List<TBsCalendarVo> list = iTBsCalendarService.queryList(bo);
        ExcelUtil.exportExcel(list, "工作日", TBsCalendarVo.class, response);
    }

    /**
     * 获取工作日详细信息
     *
     * @param natureday 主键
     */
    @SaCheckPermission("system:bsCalendar:query")
    @GetMapping("/{natureday}")
    public R<TBsCalendarVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable String natureday) {
        return R.ok(iTBsCalendarService.queryById(natureday));
    }

    /**
     * 新增工作日
     */
    @SaCheckPermission("system:bsCalendar:add")
    @Log(title = "工作日", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TBsCalendarBo bo) {
        return toAjax(iTBsCalendarService.insertByBo(bo));
    }

    /**
     * 修改工作日
     */
    @SaCheckPermission("system:bsCalendar:edit")
    @Log(title = "工作日", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TBsCalendarBo bo) {
        return toAjax(iTBsCalendarService.updateByBo(bo));
    }

    /**
     * 删除工作日
     *
     * @param naturedays 主键串
     */
    @SaCheckPermission("system:bsCalendar:remove")
    @Log(title = "工作日", businessType = BusinessType.DELETE)
    @DeleteMapping("/{naturedays}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable String[] naturedays) {
        return toAjax(iTBsCalendarService.deleteWithValidByIds(Arrays.asList(naturedays), true));
    }
}
